<?php

namespace app\admin\model;

class Classifymodel extends Commonmodel {

    protected $croomTable;

    public function __construct(array $data = [])
    {
        $this->table = 'zhjs_content_classify';
        $this->pk = 'id';
        parent::__construct($data);
        $this->croomTable = 'zhjs_classroom';
    }

    public function findAll($where = null, $pageParam = null, $num = 20){
        $whereData = [['c.is_delete' , '=', 1]];
        $paginate = ['list_rows'=>$num];

        if($where)  $whereData = array_merge($where, $whereData);
        if($pageParam = array_splice($pageParam, 1))  $paginate = array_merge($paginate, ['query'=>$pageParam]);

        $data = self::db()
            ->alias('c')
            ->leftJoin([$this->croomTable=>'cr'],'cr.id=c.cid and cr.is_delete and cr.status = 1')
            ->field('c.id, c.name, c.status, cr.name as cname, c.create_date')
            ->where($whereData)
            ->order(['c.id'=>'desc'])
            ->paginate($paginate);

        if(!$data)  return false;

        $list['page'] = $data->render();
        $dataArr = $data->toArray();
        $list['data'] = $dataArr['data'];

        return $list;
    }

}

?>